<!-- 我们的底部 -->

<template>
  <div>
    <BtnPrimary v-if="MAP.step == 1" title="A4打印机" :key="`A4${MAP.step}`" plain @click="toNext" />
    <!-- <BtnPrimary v-if="MAP.step == 1" title="标签打印机" :key="`TAG${MAP.step}`" @click="toNext" /> -->

    <BtnPrimary v-if="MAP.step == 2" title="上一步" :key="`prev${MAP.step}`" plain @click="toPrev" />
    <BtnPrimary v-if="MAP.step === 2" title="打印预览" @click="toPriview" />
  </div>
</template>

<script>
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'

// ============================== 导出组件 ============================== //

export default {
  /**
   * 名称定义 (实际使用名称)
   */
  name: 'OurFooter',

  /**
   * 混入列表 (配置选项合并)
   */
  mixins: [CORE.mixWeb()],

  /**
   * 本地方法 (轻量重要在前)
   */
  methods: {
    /**
     * 下一步
     */
    toNext() {
      const { MAP } = this
      MAP.step++
    },

    /**
     * 上一步
     */
    toPrev() {
      const { MAP } = this
      MAP.step--
    },

    /**
     * 预览
     */
    async toPriview() {
      const { param: { rowList }, MAP: { PREVIEW_URL, type, layout } } = this

      const key = `PRINT_${type.toUpperCase()}`

      sessionStorage[key] = JSON.stringify(rowList.map((row) => row[type] || {}))

      window.open(`/${PREVIEW_URL}/${type}/${layout}`)

      setTimeout(() => delete sessionStorage[key], 1000)
    },
  },
}
</script>
